package cn.xuetian.activiti.controller;

import org.activiti.engine.IdentityService;
import org.activiti.engine.identity.Group;
import org.activiti.engine.identity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhaosen
 * @date 4/2/2020
 */
@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    private IdentityService identityService;

    @GetMapping("/test1")
    public void test1() {
        //项目中每创建一个新用户，对应的要创建一个Activiti用户
        //两者的userId和userName一致
        User admin = identityService.newUser("1");
        admin.setLastName("admin");
        identityService.saveUser(admin);

        //项目中每创建一个角色，对应的要创建一个Activiti用户组
        Group adminGroup = identityService.newGroup("1");
        adminGroup.setName("admin");
        identityService.saveGroup(adminGroup);

        //用户与用户组关系绑定
        identityService.createMembership("1", "1");
    }
}
